package cn.edu.xmu.experiment.PulseComms.Service;

import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

@Service
public class UserService {

    @Autowired
    private RabbitAdmin rabbitAdmin;

    private Map<String, Boolean> userStatus = new HashMap<>();

    public void login(String username) {
        Queue queue = new Queue(username, true);
        rabbitAdmin.declareQueue(queue);
        userStatus.put(username, true);
    }

    public void logout(String username) {
        rabbitAdmin.deleteQueue(username);
        userStatus.put(username, false);
    }

    public boolean isLoggedIn(String username) {
        return userStatus.getOrDefault(username, false);
    }

}    